package bookstore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * 入力した注文情報の確認を行うActionです
 */
public class ConfirmOrderAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {

        InputOrderForm orderForm = (InputOrderForm) form;
        Order order = new OrderManager().getSessionOrder(request.getSession());
        OrderItem[] items = order.getItems();
        int[] nums = orderForm.getNums();
        for (int i = 0; i < items.length; i++) {
            items[i].setNum(nums[i]);
        }
        BeanUtils.copyProperties(order, orderForm);
        saveToken(request);
        return mapping.findForward("success");
    }

}